package com.jml.stream;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.stream.Stream;

public class Test {

    public static void main(String[] args) {
        ArrayList<String> strings = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            strings.add("i"+i);
        }
        //串行流
        Stream<String> stream = strings.stream();
        stream.forEach((t)->{
            System.out.println(Thread.currentThread().getName()+t);
        });
        HashSet<String> objects = new HashSet<>();
        //并行流
        Stream<String> stringStream = strings.parallelStream();
        stringStream.forEach((t)->{
            objects.add(Thread.currentThread().getName());
            System.out.println(Thread.currentThread().getName()+t);
        });

        System.out.println("------------------------------------------");
        System.out.println(objects);
        System.out.println(objects.size());
    }
}
